<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/12 0012
 * Time: 上午 11:49
 */

namespace App\Http\Controllers\Admin;


use App\Http\Controllers\Controller;
use App\Models\Message;
use Illuminate\Routing\Route;
use Illuminate\Routing\RouteCollection;
use Silber\Bouncer\Database\Ability;

class TestController extends Controller
{

    public function index()
    {
        $time1 = microtime(true);

        $a= '6253198407';
        $len = strlen($a);

        for ($i=0;$i<100000;$i++){
            for ($j=0;$j<$len;$j++){
                for ($k=0;$k<$len-$j;$k++){
                    if ($k == $len-1){
                        break;
                    }
                    if ($a{$k} > $a{$k+1}){
                        $tmp = $a{$k+1};
                        $a{$k+1} = $a{$k};

                        $a{$k} = $tmp;
                    }
                }

            }
        }


        $time2 = microtime(true);
        $time = $time2-$time1;
        dump($time);
    }
    public function show()
    {
        $route = app()->routes->getRoutes();
        $route = collect($route)->values('uri');
        $data = [];
        $list = [];
        foreach ($route as $key=>$item){
            $item =  collect($item)->toArray();


            $uri = $item['uri'];
            $action = $item['action'];
            if (strpos($uri,'admin')!== false ){
                $date = date('Y-m-d H:i:s');
                $data['created_at'] = $date;
                $data['updated_at'] = $date;
                $data['title'] = $uri;
                $data['name'] = $action['uses'];
                array_push($list,$data);
            }
        }

        $list = array_slice($list,8);
        $A = (new Ability())->insert($list);;
        dump($A);

    }
}